window.ColorManager = {
    Pallete: {
        aqua: { bright: "#1ABC9C", dark: "#16A085" },
        green: { bright: "#2ECC71", dark: "#27AE60" },
        blue: { bright: "#3498DB", dark: "#2980B9" },
        purple: { bright: "#9B59B6", dark: "#8E44AD" },
        black: { bright: "#34495E", dark: "#2C3E50" },
        yellow: { bright: "#F1C40F", dark: "#F39C12" },
        orange: { bright: "#E67E22", dark: "#D35400" },
        red: { bright: "#E74C3C", dark: "#C0392B" },
        white: { bright: "#ECF0F1", dark: "#BDC3C7" },
        gray: { bright: "#95A5A6", dark: "#7F8C8D" }
    }
};
Number.prototype.toHex = function () { return this.toString(16); }
ColorManager.Shade = function (option, color, value, holdRgbPoint) {
    if (option == null | option == undefined | option == NaN | option == "" | option == {} | option == 0)
        option = "vader";

    var isDarken = option == "vader";
    var isHex = false;
    var isRgb = false;
    if (color.indexOf("#") == 0)
        isHex = true;

    var r = isHex ? parseInt(color.substring(1, 3), 16) : parseInt(color.substring(4, color.length - 1).split(",")[0]);
    var g = isHex ? parseInt(color.substring(3, 5), 16) : parseInt(color.substring(4, color.length - 1).split(",")[1]);
    var b = isHex ? parseInt(color.substring(5, 7), 16) : parseInt(color.substring(4, color.length - 1).split(",")[2]);

    if (value > 0 && value < 1) {
        r = isDarken ? parseInt(r * value) : parseInt(r * (value + 1));
        g = isDarken ? parseInt(g * value) : parseInt(g * (value + 1));
        b = isDarken ? parseInt(b * value) : parseInt(b * (value + 1));
    } else {
        if (value > 0 && value < 256)
            value = parseInt(value);
        else
            value = 32;

        if (holdRgbPoint) {
            if (!isDarken && (r + value) >= 255)
                value = 255 - r;
            if (!isDarken && (g + value) >= 255)
                value = 255 - g;
            if (!isDarken && (b + value) >= 255)
                value = 255 - b;
            if (isDarken && (r - value) <= 0)
                value = r;
            if (isDarken && (g - value) <= 0)
                value = g;
            if (isDarken && (b - value) <= 0)
                value = b;
        }

        r = isDarken ? r - value : r + value;
        g = isDarken ? g - value : g + value;
        b = isDarken ? b - value : b + value;
    }

    if (r < 0) r = 0;
    if (g < 0) g = 0;
    if (b < 0) b = 0;
    if (r > 255) r = 255;
    if (g > 255) g = 255;
    if (b > 255) b = 255;

    if (isHex)
        return "#" +
            (r.toHex().length < 2 ? "0" + r.toHex() : r.toHex())
            + (g.toHex().length < 2 ? "0" + g.toHex() : g.toHex()) 
            + (b.toHex().length < 2 ? "0" + b.toHex() : b.toHex());
    return "rgb(" + r.toString() + "," + g.toString() + "," + b.toString() + ")";
}
ColorManager.DarkenColor = function (color, value, holdRgbPoint) {
    return ColorManager.Shade("vader", color, value, holdRgbPoint);
}
ColorManager.BrightenColor = function (color, value, holdRgbPoint) {
    return ColorManager.Shade("luke", color, value, holdRgbPoint);
}
String.prototype.darkenColor = function (value, holdRgbPoint) {
    return ColorManager.DarkenColor(this, value, holdRgbPoint);
};
String.prototype.brightenColor = function (value, holdRgbPoint) {
    return ColorManager.BrightenColor(this, value, holdRgbPoint);
};